package com.definity.toolkit.web.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import br.com.caelum.vraptor.Result;

import com.definity.security.common.User;
import com.definity.toolkit.web.security.MockUser;

public class JaasSecurityInterceptor extends AbstractSecurityInterceptor {

	public JaasSecurityInterceptor(Result result, HttpServletRequest request) {
		super(result, request);
	}

	@Override
	protected boolean hasRoles(User user, List<String> roleNames) {
		for (String roleName : roleNames) {
			if (request.isUserInRole(roleName))
				return true;
		}
		return false;
	}

	@Override
	protected User getUser() {
		if (request.getRemoteUser() == null)
			return null;
		return new MockUser(request.getRemoteUser());
	}

}
